package org.harsh.transmission.common;

import cn.hutool.core.date.DateUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * Created by liuhaibo on 2024/6/12.
 */
@Data
@Slf4j
@Deprecated
public class NettyMsgHead {
    public static short startSign = (short) 0xFFFF;
    private byte msgType;
    private long timeStamp;

    public NettyMsgHead(int msgType) {
        // todo need to check msgType value
        this.msgType = (byte) msgType;
        this.timeStamp = DateUtil.date().getTime();
    }

    public NettyMsgHead(byte msgType, long timeStamp) {
        this.msgType = msgType;
        this.timeStamp = timeStamp;
    }

    public byte[] buildNettyMsgHead() {
        byte[] msgHead = new byte[11];
        msgHead[0] = (byte) 0xff;
        msgHead[1] = (byte) 0xff;
        msgHead[2] = msgType;
        for (int i = 0; i < 8; i++) {
            int offset = 64 - (i + 1) * 8;
            msgHead[i + 3] = (byte) ((timeStamp >> offset) & 0xff);
        }
        return msgHead;
    }

}
